#ifndef POPUPSERVICE_H_
#define POPUPSERVICE_H_

#include "../../core/Buddy.h"
#include "../../core/database/DBModule.h"
#include "../../core/events/StatusEvent.h"
#include "../../core/events/MessageEvent.h"
#include "../../core/events/TypingNotificationEvent.h"
#include "../../core/events/SettingChangedEvent.h"
#include "../../core/interfaces/iModule.h"
#include <vector>
#include "Popup.h"



namespace Impp
{

enum PopupPosition{
	POPUP_POS_LEFT_TOP = 1,
	POPUP_POS_LEFT_BOTTOM = 2,
	POPUP_POS_RIGHT_TOP	= 3,
	POPUP_POS_RIGHT_BOTTOM = 4
};

#define POPUPS_DB_ENABLED				wxT("popups")
#define POPUPS_DB_POSITION 				wxT("position")
#define POPUPS_DB_SHOW_GOES_ONLINE 		wxT("goesOnline")
#define POPUPS_DB_SHOW_GOES_OFFLINE 	wxT("goesOffline")
#define POPUPS_DB_SHOW_ISTYPING 		wxT("isTyping")
#define POPUPS_DB_SHOW_STATUS_CHANGED	wxT("statusChanged")
#define POPUPS_DB_SHOW_MESSAGE_IN		wxT("messageIn")

#define POPUPS_DB_POPUP_ALPHA			wxT("alpha")
#define POPUPS_DB_POPUP_COLOR			wxT("color")


class Popup;

class PopupService : private wxTimer
{
private:
	wxFrame* dummyParentFrame;
	std::vector<Popup*> popups;
	int position;
	wxSize defaultPopupSize;
	DBModule popupsDB;
	bool enabled;
	bool goesOnline;
	bool goesOffline;
	bool isTyping;
	bool statusChanged;
	bool messageIn;
	int alpha;
	bool color;

	wxColor colorGoesOnline;
	wxColor colorGoesOffline;
	wxColor colorIsTyping;
	wxColor colorStatusChanged;
	wxColor colorMessageIn;

public:
	PopupService();
	virtual ~PopupService();

	void showPopup(const wxString & txt,const wxColor & color, int time);
	void showPopup(Buddy* buddy,const wxString & txt,const wxColor & color, int time);
	void hidePopup(Popup* popup);

	void showGoingOnlinePopup(Buddy* buddy,const Status & oldStatus);
	void showGoingOfflinePopup(Buddy* buddy,const Status & oldStatus);
	void showIsTypingPopup(Buddy* buddy);
	void showStatusChangedPopup(Buddy* buddy, const Status & newStatus, const Status & oldStatus);
	void showMessageInPopup(Buddy* buddy, const wxString & message);

	void setEnabled(bool enabled);
	void setPopupPosition(const PopupPosition & pos);
	void setShowPopupOnGoingOnline(bool show);
	void setShowPopupOnGoingOffline(bool show);
	void setShowPopupIsTyping(bool show);
	void setShowPopupOnStatusChanged(bool show);
	void setShowPopupOnMessageIn(bool show);

	void onStatusChanged(StatusEvent & event);
	void onMessageIn(MessageEvent & event);
	void onTypingNotification(TypingNotificationEvent & event);
	void onSettingChanged(SettingChangedEvent & event);
public:
	wxFrame* getDummyFrame();
	bool useColor();
	int getAlpha();

private:
	void Notify();

};

class StdPopupModule : public iModule{

	DECLARE_DYNAMIC_CLASS(StdPopupModule)

private:
	PopupService* popupService;

public:
	StdPopupModule() :
		popupService(NULL){};
	virtual ~StdPopupModule(){};

	virtual void moduleInit(){
		popupService = new PopupService();
	};

	virtual void moduleDestroy(){
		wxDELETE(popupService);
	}
};

}

#endif /*POPUPSERVICE_H_*/
